package com.lms.lambda;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-12 08:05
 * @Description: ${Description}
 */
public class PredicateDemo {
    public static void main(String[] args) {
        Predicate<Integer> predicate = i -> i > 5;
        boolean test = predicate.test(5);
        System.out.println(test);
        Predicate<Integer> or = predicate.or(Objects::nonNull);//或运算
//        default Predicate<T> or(Predicate<? super T> other) {
//            Objects.requireNonNull(other);
//            return (t) -> test(t) || other.test(t);
//        }
        System.out.println(or.test(5));  //5>5 || Objects.nonNUll(5)
        Predicate<Integer> and = predicate.and(Objects::isNull);
        System.out.println(and.test(6)); //6>5 && Objects.isNull(6)
        Predicate<Integer> negate = and.negate();
        System.out.println(negate.test(6));//! (6>5 && Objects.isNull(6))  返回表示此谓词的逻辑否定的谓词。
        Predicate<Object> equal = Predicate.isEqual(new Object());//返回根据 Objects.equals(Object, Object)测试两个参数是否相等的 谓词 。
        System.out.println(equal.test(new Object()));


    }
}
